Skip to content

docs: clarify that supportingFiles is an allow-list (#22238) - #25075

Open
brbousnguar wants to merge 2 commits into
OpenAPITools:masterfrom
brbousnguar:forge/22238-bug-java-serverconfiguration-is
Open

brbousnguar wants to merge 2 commits into
OpenAPITools:masterfrom
brbousnguar:forge/22238-bug-java-serverconfiguration-is

Conversation

@brbousnguar

@brbousnguar brbousnguar commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Closes #22238.

What is actually going on

#22238 reports that the restclient library generates an ApiClient which
references ServerConfiguration / ServerVariable without those classes being
available, and suggests adding imports. Two things about that:

  • They are in the same package as ApiClient (invokerPackage), so an
    import would not help — and would not compile.
  • They are already registered as supporting files, and have been since
    [java] Support templated servers #4998: JavaClientCodegen.java:572-573 adds ServerConfiguration.mustache
    and ServerVariable.mustache, and :764 adds ExceptionProvider.mustache
    for restclient. A default run emits all of them next to ApiClient.java.

The reporter's build fails because of their own Maven configuration:

<supportingFilesToGenerate>ApiClient.java,Authentication.java,HttpBasicAuth.java,HttpBearerAuth.java,ApiKeyAuth.java,JavaTimeFormatter.java,RFC3339DateFormat.java</supportingFilesToGenerate>

That maps to the supportingFiles global property, which DefaultGenerator
treats as a fixed allow-list:

shouldGenerate = supportingFilesToGenerate.contains(support.getDestinationFilename());

The list was written before #21699 taught the restclient ApiClient about
servers, so ServerConfiguration.java, ServerVariable.java and
ExceptionProvider.java are now skipped while the emitted ApiClient still
references them. Reproduced with the CLI equivalent on a minimal spec: with
--global-property supportingFiles="ApiClient.java:..." exactly those three
files are missing from the output; without it, they are all generated and also
listed in .openapi-generator/FILES. @BobLuursema reached the same conclusion
in the issue thread.

So there is no generation bug to fix — but the trap is undocumented in the
places a user actually reads, and the Maven plugin's own Javadoc for the
option describes the wrong thing. This PR fixes that.

Changes

  • docs/customization.md — new paragraph in Selective generation noting that
    an explicit list replaces the full set rather than adding to it, that
    supporting files reference one another (with the restclient ApiClient
    example), that each skip is logged at INFO level, and that
    .openapi-generator-ignore is the upgrade-safe alternative.
  • docs/global-properties.md — one-line cross-reference to that caveat, since
    this is where supportingFiles is documented as a global property and where a
    user building the list reads first.
  • CodeGenMojo.java — the Javadoc on supportingFilesToGenerate read "A comma
    separated list of models to generate. All models is the default."
    , copy-pasted
    from modelsToGenerate. Corrected, with the same caveat.
  • modules/openapi-generator-maven-plugin/README.md — caveat added to the
    supportingFilesToGenerate row.
  • JavaClientCodegenTest — two tests:
    • testRestClientSupportingFilesAllowListSkipsApiClientCompanions_issue_22238
      reproduces the reported configuration: with the supportingFiles global
      property set to ApiClient.java, ApiClient.java is still emitted while the
      ServerConfiguration, ServerVariable and ExceptionProvider it references
      are skipped. This pins and documents the footgun itself.
    • testRestClientDefaultGenerationIncludesCompanionFiles pins the premise the
      issue assumed had regressed — a default restclient run emits all four files
      side by side — so the registration cannot silently disappear.

No generator behaviour changes, so samples/ is untouched.

Testing

./mvnw -pl modules/openapi-generator -Dtest='JavaClientCodegenTest#testRestClientDefaultGenerationIncludesCompanionFiles+testRestClientSupportingFilesAllowListSkipsApiClientCompanions_issue_22238' clean test
./mvnw -pl modules/openapi-generator,modules/openapi-generator-maven-plugin clean test
./mvnw -pl modules/openapi-generator,modules/openapi-generator-maven-plugin checkstyle:check -Dcheckstyle.includeTestSourceDirectory=true

All green: the core library reports Tests run: 5270, Failures: 0, Errors: 0, Skipped: 14 with JavaClientCodegenTest at 299/0, the Maven plugin module
reports 27/0, and checkstyle passes with test sources included.

I also checked the default-generation test is meaningful: commenting out the
ServerConfiguration.mustache registration in JavaClientCodegen makes it fail
with File does not exist when it should: .../ServerConfiguration.java.

One note for anyone reproducing locally, since it cost me a round: the clean is
load-bearing. This repo enables the Develocity Maven extension with the local
build cache on, and a cached target/classes from before #24783 still contained
the ~30 mustache templates that commit moved from cpp-boost-beast-client/ to
cpp-boost-beast-common/. Maven's resources plugin never deletes removed files,
so the template locator resolved the stale copies and three unrelated tests
failed (cppboostbeast.ModelApiSurfaceTest and both
templating.GeneratorTemplateContentLocatorAdditionalDirsTest methods). They
pass on a clean build. Relatedly, mvn ... test compile cannot be used here at
all: the second lifecycle pass recompiles the antlr4-generated
KotlinLexer/KotlinParser against the compile classpath, where
antlr4-runtime is test-scoped, and it fails before the reactor reaches the
Maven plugin module.

PR checklist

  • Read the contribution guidelines.
  • Ran the build; samples and generator docs are unchanged by this PR
    (documentation and tests only), so there is nothing to regenerate.
  • @Nicklas2751 (Java Spring 6 RestClient) — tagging you since the example in
    the docs is the restclient ApiClient you maintain; happy to reword.

Summary by cubic

Documents that the supportingFiles option is a fixed allow-list, not an addition, so an explicit list skips supporting files a newer generator version adds — which is what broke the build reported in #22238.

  • Adds a paragraph to the selective generation docs, a cross-reference in docs/global-properties.md, and a recommendation to use .openapi-generator-ignore as the upgrade-safe alternative.
  • Corrects the CodeGenMojo Javadoc for supportingFilesToGenerate (previously copy-pasted from modelsToGenerate) and the corresponding Maven plugin README row.
  • The global-properties note states that supportingFiles, models, and apis are all allow-lists, but scopes the generator-upgrade warning to supportingFiles, since only its names are owned by the generator.
  • Adds two tests: one reproducing the reported configuration to pin the allow-list behavior, and one verifying a default restclient run emits all referenced files.

No generator behavior changes; samples/ is untouched.

Written for commit 608b42c. Summary will update on new commits.

Review in cubic

OpenAPITools#22238 reports that the restclient ApiClient references ServerConfiguration,
ServerVariable and ExceptionProvider without those classes being available.
They are registered as supporting files and live in the same package as
ApiClient, so a default run emits all of them and there is nothing to import.
The reported build fails because its <supportingFilesToGenerate> list predates
the ApiClient gaining those references, and DefaultGenerator treats the list as
a fixed allow-list, so the three files are skipped.

Document that trap where it is read: a paragraph in the Selective generation
section of docs/customization.md with the restclient example and a pointer to
.openapi-generator-ignore, and a cross-reference from docs/global-properties.md.
Correct the Javadoc on CodeGenMojo#supportingFilesToGenerate, which described
modelsToGenerate instead, and add the same caveat to the Maven plugin README.

Add two tests to JavaClientCodegenTest: one reproducing the reported
configuration, where setting the supportingFiles global property to
ApiClient.java emits ApiClient.java while skipping the three companions it
references, and one pinning the premise the issue assumed had regressed, that a
default restclient run emits all four files side by side.

No generator behaviour change, so samples are untouched.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 5 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread docs/global-properties.md Outdated
Comment thread docs/global-properties.md Outdated
The note added under the global-properties table applied the "a newer
generator version adds files an older list does not mention" warning to
supportingFiles, models and apis alike. Only supportingFiles behaves that way:
its names are template/supporting-file names owned by the generator, so a
generator upgrade can introduce one. The models and apis lists filter names
that come from the user's OpenAPI document, which a generator upgrade does not
change.

State the allow-list semantics for all three, then scope the upgrade warning to
supportingFiles, and reword the sentence so it parses.
@brbousnguar

Copy link
Copy Markdown
Contributor Author

Thanks — both addressed.

  1. Reworded: "files a newer version of a generator added are not generated" → "files added by a newer version of a generator are not generated unless the list mentions them."
  2. Scoped the generator-upgrade caveat to supportingFiles specifically, rather than applying it to models/apis too — those filter by model/API names from the user's OpenAPI spec, which is a different kind of change than a generator version bump adding a new internal template file (what [BUG][Java] ServerConfiguration is not included in imports when generating from simple OpenAPI file #22238 hit).

One open question from this round's internal review, flagging rather than guessing: the sentence now reads "when one of them is set, only the names it lists are generated" — worth confirming the bare-flag form (e.g. --global-property supportingFiles with no colon-separated list) doesn't mean "generate all of that category" rather than "generate none/error." I didn't verify this against DefaultGenerator/GlobalSettings this round; happy to fix the wording if it's wrong.

@Nicklas2751 Nicklas2751 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brbousnguar Thank you for your contribution! Good work. I have no complaints. @wing328 I suggest merging the PR like this. :)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG][Java] ServerConfiguration is not included in imports when generating from simple OpenAPI file

2 participants